home *** CD-ROM | disk | FTP | other *** search
- #include <Common.h>
- #include <System/SysAll.h>
- #include <UI/UIAll.h>
- #include "util.h"
-
- /* Define OS2.0 so that OS 1.0 can be checked for.
- Special processing is required if app not allowed
- to run under PalmOS 1.0 */
- #define Version20 sysMakeROMVersion (2, 0, 0, 0, 0)
- #define BITS_SET(w,b) (((w) & (b)) == (b))
- /* Stuff used to export to MemoPad */
- #define firstRecord 0
- #define memoPadAppType 'memo'
- #define memoPadDBType 'DATA'
- #define memoPadDBName "MemoDB"
- #define memoPadMaxChar 4000
-
- /*************************************************************
- *
- * NAME: Id2Ptr
- *
- * DESCRIPTION: This routine is is used to convert an object ID
- * into a pointer to the object.
- *
- * REVISION HISTORY:
- * Name Date Description
- * ---- -------- -----------
- * kld 5 Nov 98 Initial Revision
- *
- *************************************************************/
- VoidPtr Id2Ptr( Word wID )
- {
- return( FrmGetObjectPtr( FrmGetActiveForm(),
- FrmGetObjectIndex( FrmGetActiveForm(), wID ) ) );
- }
-
-
- /*************************************************************
- *
- * NAME: CheckRomVersion
- *
- * DESCRIPTION: This routine checks that a ROM version meets the
- * minimum requirement.
- *
- * REVISION HISTORY:
- * Name Date Description
- * ---- -------- -----------
- * kld 5 Nov 98 Initial Revision
- *
- *************************************************************/
- Err CheckRomVersion(DWord requiredVersion, Word launchFlags)
- {
- DWord romVersion;
-
- /* Get the ROM version for which PalmOS version is being used. */
- FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
- if (romVersion >= requiredVersion)
- return (0);
-
-
- /* If the user launched the app from the launcher, explain
- why the app shouldn't run using FrmAlert. */
- if (BITS_SET(launchFlags, sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
- {
- FrmAlert (RomIncompatibleAlert);
- if (romVersion < Version20)
- {
- Err err; // Why is this var needed? See <AppLaunchCmd.h>!
- AppLaunchWithCommand(sysFileCDefaultApp,
- sysAppLaunchCmdNormalLaunch,
- NULL);
- }
- }
-
- return (sysErrRomIncompatible);
- }
-
-
- /*************************************************************
- *
- * NAME: ExportToMemoPad
- *
- * DESCRIPTION: This routine is used to export the string with
- * the given handle to the memo pad
- *
- * TODO: Check for the string length not to exceed max size
- * allowed in one memopad record.
- *
- *
- * REVISION HISTORY:
- * Name Date Description
- * ---- --------- -----------
- * kld 25 Nov 98 Initial Revision
- *
- *************************************************************/
- Int ExportToMemoPad(VoidHand hndExportText)
- {
- UInt record = firstRecord;
- VoidHand hndNew;
- DmOpenRef pdbMemoPad;
- Word length;
- CharPtr sExportText;
-
- /* Open MemoPad database */
- pdbMemoPad = DmOpenDatabaseByTypeCreator(memoPadDBType, memoPadAppType, dmModeReadWrite);
- if (!pdbMemoPad)
- {
- FrmAlert(NoMemoPadAlert);
- return 1;
- }
-
- /* Create New MemoPad record */
- sExportText = (CharPtr) MemHandleLock(hndExportText);
- length = StrLen(sExportText);
- if (length > memoPadMaxChar)
- {
- FrmAlert(ExportSizeAlert);
- return 3;
- }
- record = 0; // at index 0 in MemoPad database
- hndNew = DmNewRecord(pdbMemoPad, &record, length+1);
-
- if (!hndNew)
- {
- FrmAlert(ErrorExportingAlert);
- return 2;
- }
-
- DmWrite(MemHandleLock(hndNew), 0, MemHandleLock(hndExportText), length+1);
- MemHandleUnlock(hndExportText);
- MemHandleUnlock(hndNew);
- DmReleaseRecord(pdbMemoPad, record, true);
- DmCloseDatabase(pdbMemoPad);
-
- return 0;
- }
-